package cn.pzhu.jspdb.dao;

import java.sql.*;

public class BaseDao {
	public final static String url="jdbc:mysql://localhost:3306/2012jb?useUnicode=true&characterEncoding=UTF-8";
	public final static String userName="root";
	public final static String password="123456";
	//static block 
	static{
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	public Connection getConnection() throws SQLException{
		return DriverManager.getConnection(url, userName, password);
	}
	public void close(Statement st,Connection conn){
		close(null,st,conn);
	}
	public void close(ResultSet rs,Statement st,Connection conn){
		if(rs!=null){
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if(st!=null){
			try {
				st.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if(conn!=null){
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
}
